<template>
  <drawRightsTemp
    :equityGroups="trialRightPackage"
    :btnText="$t('guide.now')"
    @btnClick="onOpenLogin"
    @wndClose="onClose">
    <div slot="important2">
      <i18n path="guide.free" :tag="false">
          <span place="many" style="color:#FF2B2B;">{{ trialRightPackage | importantPackageName(true, $t('guide.many'))}}</span>
      </i18n>
    </div>
  </drawRightsTemp>
</template>
<script>
import mixin from './mixins'
export default {
  mixins: [mixin],
  data () {
    return {
      trialRightPackage: []
    }
  },
  computed: {
    statIds () {
      return this.isNewInstall ? {
        show: 2526,
        login: 2527,
        close: 2528,
        c_login: 2529,
        c_nologin: 2530,
        c_close: 2531
      } : {
        show: 2586,
        login: 2587,
        close: 2588,
        c_login: 2589,
        c_nologin: 2590,
        c_close: 2591
      }
    }
  },
  mounted () {
    this.$xz('xz_substat_action', this.statIds.show)
    this.getPackagesList({ pid: this.appInfo.allPackages }).then(res => {
      this.trialRightPackage = res.data.list || []
    })
  },
  methods: {
    onOpenLogin () {
      this.$xz('xz_substat_action', this.statIds.login)
      this.openLogin()
    },
    onClose () {
      this.$xz('xz_substat_action', this.statIds.close)
      this.$PsMessageBox({
        customClass: 'message-white no-modal',
        distinguishCancelAndClose: true,
        center: true,
        modal: false,
        confirmButtonText: this.$t('guide.nonLogin'),
        confirmButtonClass: 'cancel',
        cancelButtonText: this.$t('guide.continue'),
        cancelButtonClass: 'el-button--primary',
        message: `${this.$t('guide.receive')}`,
        beforeClose: (action, instance, done) => {
          if (action === 'confirm') {
            this.$xz('xz_substat_action', this.statIds.c_nologin)
            this.openIntroduct()
          } else if (action === 'cancel') {
            this.$xz('xz_substat_action', this.statIds.c_login)
            this.openLogin()
          } else {
            this.$xz('xz_substat_action', this.statIds.c_close)
          }
          done()
        }
      })
    }
  }
}
</script>
